import React, { PureComponent, Fragment } from 'react';
import { connect } from 'dva';
import {
  Card,
  Form,
} from 'antd';
import StandardTable from '@/components/StandardTable';
import PageHeaderWrapper from '@/components/PageHeaderWrapper';
import styles from '../UserManage.less';
import { powerBtnFunc } from '@/utils/utils';


/* eslint react/no-multi-comp:0 */
@connect(({ Product, loading }) => ({
  Product,
  loading: loading.models.Product,
}))

@Form.create()
class Product extends PureComponent {
  state = {
    modalVisible: false,
    updateModalVisible: false,
    lookDescView: false,
    selectedRows: {},
    formValues: {},
  };

  status(val) {
    let str = '';
    if (val === 1) {
      str = '未发布';
    } else {
      str = val === 2 ? '部分发布' : '全部发布';
    }
    return (<span>{str}</span>);
  }

  columns = [
    {
      title: '产品编号',
      dataIndex: 'productNo',
    },
    {
      title: '产品名称',
      dataIndex: 'productName',
    },

    {
      title: '金额',
      dataIndex: 'amount',

    },
    {
      title: '发布金额',
      dataIndex: 'publishAmount',
    },
    {
      title: '天数',
      dataIndex: 'totalDays',
    },
    {
      title: '费率',
      dataIndex: 'rate',
    },
    {
      title: '总服务费',
      dataIndex: 'totalServiceFee',
    },

    {
      title: '创建人',
      dataIndex: 'createName',
    },
    {
      title: '创建人名称',
      dataIndex: 'createTime',
    },
    {
      title: '发布状态 ',
      dataIndex: 'publishStatus',
      render: val => (this.status(val)),
    },
  ];

  constructor(props) {
    super(props);
  }

  componentDidMount() {
    const { dispatch } = this.props;
    dispatch({
      type: 'Product/fetch',
    });
  }

  handleStandardTableChange = (pagination, filtersArg, sorter) => {
    const { dispatch } = this.props;
    const { formValues } = this.state;


    const params = {
      pageNo: pagination.current,
      pageSize: 15,
      ...formValues,
    };

    dispatch({
      type: 'Product/fetch',
      payload: params,
    });
  };


  render() {
    const { Product: { data }, loading } = this.props;

    return (
      <PageHeaderWrapper title="产品管理">
        <Card bordered={false}>
          <div className={styles.tableList}>
            <StandardTable
              selectedRows={[]}
              loading={loading}
              data={data ? data : []}
              rowKey={'projectNo'}
              rowSelectHide={true}
              columns={this.columns}
              onChange={this.handleStandardTableChange}
            />
          </div>
        </Card>

      </PageHeaderWrapper>
    );
  }
}

export default Product;
